<?php
/**
 * Created by PhpStorm.
 * User: hansliao
 * Date: 2018/2/7
 * Time: 11:29
 */
namespace Admin\Controller;

class WechatUsersController extends AdminController{

    protected function _initialize(){
        parent::_initialize();
        //$this->uid = $_SESSION['onethink_admin']['user_auth']['uid'];
    }

    public function index(){
        $status = I('get.status',1);
        if($status>0){
            $where ='status > 0';
        }else{
            $where ='status <= 0';
        }
        if(I('get.nickname')){
            $nn = base64_encode(I('get.nickname'));
            $where .= " and nickname like '%$nn%'";
        }
        $rs = $this->lists('wechat_users',$where,'id desc',array());
        foreach($rs as $k=>$v){
            $rs[$k]['nickname'] = base64_decode($v['nickname']);
        }
        if($status>0){
            $this->assign('title','已授权业务员');
        }else{
            $this->assign('title','待授权列表');
        }

        $this->assign('users',$rs);
        $this->display();
    }

    public function delete($mid){
        if(M('wechat_users')->where("id = $mid")->setField('status',-1)){
            $this->success('操作成功！');
        }else{
            $this->success('操作失败！');
        }
    }
    public function setywy(){
        $data = array();
        $data['cname'] = I('post.cname');
        $data['ywym'] = I('post.ywym');
        $data['status'] = 1;
        $mid = I('post.mid');
        if(M('wechat_users')->where("id = $mid")->save($data)){
            $this->success('操作成功！');
        }else{
            $this->success('操作失败！');
        }
    }
}